<?php		
/*
**********************************************
JoomLeague EVENTS STATISTIC MODULE
Copyright (c) 2007 JoomLeague.de
**********************************************
This program is free software; you can redistribute it and/or modify 
it under the terms of the GNU General Public License as published by 
the Free Software Foundation; either version 2 of the License, or 
(at your option) any later version.

This header must not be removed. Additional contributions/changes
may be added to this header as long as no information is deleted.
**********************************************

* EVENTS STATISTIC MODULE
*
* 2007-07-31 - Version 0.90
*
* Displays a selected eventtype list (e.g. goals or yellow cards) for the 
* choosen project.
* There are some options for this module, which can be set in the 
* "Parameters" section of the module in Administration.
*

**********************************************
Get the latest version of JoomLeague at:
http://www.joomleague.de//
**********************************************
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

if (file_exists($mosConfig_absolute_path.'/components/com_joomleague/language/'.$mosConfig_lang.'.php')) {
  include_once($mosConfig_absolute_path.'/components/com_joomleague/language/'.$mosConfig_lang.'.php');
} 
else{
  include_once($mosConfig_absolute_path.'/components/com_joomleague/language/english.php');
}

require_once 'administrator/components/com_joomleague/joomleague.class.php';

$params = mosParseParams( $module->params );
$show = (isset($params->show)) ? $params->show : 0; //default 0
$p = $params->project;

$project = new JoomLeague( $database );
$project->load($p);

$eventtype = intval($params->eventtype);
$limit = intval($params->limit);

$query = sprintf("SELECT SUM(event_sum) AS value, p.firstname, p.lastname, t.short_name as team
            FROM #__joomleague_match_events AS me, #__joomleague_players AS p, #__joomleague_teams AS t, #__joomleague_playertool AS pt
           WHERE me.player_id = p.id AND 
                 me.player_id = pt.player_id AND 
                 pt.team_id = t.id AND 
                 pt.project_id = me.project_id AND
                 me.event_type_id =%s AND 
                 me.project_id =%s
        GROUP BY me.player_id
        ORDER BY value DESC  LIMIT 0 , %s",$eventtype, $project->id, $limit);
$database->setQuery($query);
$rows = $database->loadObjectList();

?>
<?php if($show == 1){?><div align="center"><b><?php echo $project->name;?></b></div><?php };?>

<table width="100%" align="center" border="0" cellpadding="2" cellspacing="0">
<?php
  				
    $k = 0;
    foreach($rows as $row){
    
      $class = ($k == 0)? 'sectiontableentry1' : 'sectiontableentry2';
    
?>
  <tr class="<?php print $class;?>">
    <td align="left"><?php echo sprintf("%s %s (%s)",$row->firstname, $row->lastname, $row->team);?></td>
    <td>&nbsp;</td>
    <td align="right"><?php echo $row->value;?></td>
  </tr>
<?php     
      $k = 1 - $k;
    }
?>

</table>
